import React, { useState } from "react";
import "./login.less";
import { Input, Grid, Modal,Button } from "antd-mobile";
import request from "./../utils/request";
export default () => {
  const [code, setcode] = useState("");
  const [pwd, setpwd] = useState("");
  const [loginLoading, setloginLoading] = useState(false);
  const login = () => {
    if (code == "") {
      Modal.alert({
        content: "请输入账号",
        onConfirm: () => {
          console.log("Confirmed");
        },
      });
      return;
    }
    if (pwd == "") {
      Modal.alert({
        content: "请输入密码",
        onConfirm: () => {
          console.log("Confirmed");
        },
      });
      return;
    }
    request("/shopuser/login", {
      code: code,
      pwd: pwd,
      type: "account",
    }).then((res) => {
        console.log(res);
        
      if (res.code == 0) {
        window.localStorage.setItem("userInfo", JSON.stringify(res.data));
        setTimeout(() => {
            window.location.href = window.location.origin+window.location.pathname + "#/home";
        }, 200);
        
      }
    });
  };
  const toSys = () => {
   setloginLoading(true)
  };
  return (
    <>
      {loginLoading ? (
        <div className="loginPage">
          <div className="loginDesc">输入账号登录</div>
          <div className="loginForm">
            <div className="loginItem">
              <div className="loginFormLabel">账号</div>
              <div className="loginFormInput">
                <Input
                  value={code}
                  onChange={(e) => setcode(e)}
                  placeholder="请输入账号"
                />
              </div>
            </div>
            <div className="loginItem">
              <div className="loginFormLabel">密码</div>
              <div className="loginFormInput">
                <Input
                  value={pwd}
                  onChange={(e) => setpwd(e)}
                  placeholder="请输入密码"
                />
              </div>
            </div>
          </div>
          <div className="loginAction">
            <div className="successButton" onClick={login}>
              登录
            </div>
          </div>
        </div>
      ) : (
        <div className={'logins'}>
            <div className={'logoPng'}>
              <img src={require("./index_logo.png")} alt="" />
            </div>
            <div className={'hxxt'}>核销系统</div>

            <div className={'login_btn_wrap'}>
              {/* <div className={styles.auto_login}>
              <div className={styles.select_auto_login+'  between_flex'} style={{marginLeft:'3px'}}>
                <Checkbox>
                  <span className="auto_login_text">
                    5天内自动登录
                </span>
                </Checkbox>
                <span className="forgot_password">
                  忘记密码
                </span>
              </div>
            </div> */}
              <Button
                onClick={toSys}
                className={'login_btn'}
              >
                进入系统
              </Button>
            </div>
          </div>
      )}
    </>
  );
};
